class Scroller extends Plugin {
    constructor()
    {
        super();
        this.scroller = scrollama();
    }
    
    onMapLoaded () {
        // setup the instance, pass callback functions
        this.scroller
            .setup({
                step: '.step',
                offset: 0.5,
                progress: true
            })
            .onStepEnter(response => {
                var chapter = mapbook.config.chapters.find(chap => chap.id === response.element.id);
                response.element.classList.add('active');
                mapbook.map.flyTo(chapter.location);
                if (chapter.onChapterEnter.length > 0) {
                    chapter.onChapterEnter.forEach(mapbook.setLayerOpacity);
                }
            })
            .onStepExit(response => {
                var chapter = mapbook.config.chapters.find(chap => chap.id === response.element.id);
                response.element.classList.remove('active');
                if (chapter.onChapterExit.length > 0) {
                    chapter.onChapterExit.forEach(mapbook.setLayerOpacity);
                }
            });
        // setup resize event
        window.addEventListener('resize', this.scroller.resize);
    }
}
